package com.itheima.service.impl;

import com.itheima.mapper.EmpMapper;
import com.itheima.mapper.StudentMapper;
import com.itheima.pojo.JobOption;
import com.itheima.pojo.StudentOption;
import com.itheima.service.ReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Service
public class ReportServiceImpl implements ReportService {

    @Autowired
    private EmpMapper empMapper;

    @Autowired
    private StudentMapper studentMapper;


    /***
     * 班级人数统计
     * @return
     */
    @Override
    public StudentOption getStudentCountData() {
        //查询数据
        List<Map<String,Object>> list = studentMapper.countStudentCountData();

        //转换数据
        return new StudentOption(
                list.stream().map(m->m.get("name")).collect(Collectors.toList()),
                list.stream().map(m->m.get("num")).collect(Collectors.toList())
        );
    }

    /***
     * 学员学历统计
     * @return
     */
    @Override
    public List<Map> getStudentDegreeData() {
        return studentMapper.countStudentDegreeData();
    }

    /***
     * 性别统计
     * @return
     */
    @Override
    public List<Map> getEmpGenderData() {
        return empMapper.countEmpGenderData();
    }

    /***
     * 职位数量统计
     * @return
     */
    @Override
    public JobOption getJobEmpData() {
        //1）调用Dao查询数据  List<Map>
        List<Map<String,Object>> list = empMapper.countJobEmpData();

        //2）将List<Map>转成JobOption
        List<Object> jobList = list.stream().map(m -> m.get("pos")).collect(Collectors.toList());
        List<Object> dataList = list.stream().map(m -> m.get("num")).collect(Collectors.toList());
        return new JobOption(jobList,dataList);
    }


}
